import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

class UserSynopsis extends StatefulWidget {
  //用户简介条目
  final nickName;
  final description;
  final avatar;
  final trall;
  UserSynopsis(
      {this.nickName = "昵称xxx",
      this.description = "添加个人描述，让更多的人认识你",
      this.avatar = 'images/defautAvatar.jpg',
      this.trall});

  @override
  _UserSynopsisState createState() => _UserSynopsisState();
}

class _UserSynopsisState extends State<UserSynopsis> {
  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: CircleAvatar(
        child: Image.asset(widget.avatar),
      ),
      title: Text(this.widget.nickName),
      subtitle: Text(this.widget.description),
      trailing: widget.trall,
    );
  }
}

class PhotoViewSimpleScreen extends StatelessWidget {
  //完整图片浏览
  final imageProvider,
      minScale,
      maxScale,
      heroTag,
      loadingChild,
      backgroundDecoration;

  const PhotoViewSimpleScreen(
      {this.imageProvider,
      this.minScale = 0.5,
      this.maxScale = 1.0,
      this.heroTag = 1,
      this.backgroundDecoration,
      this.loadingChild});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        constraints: BoxConstraints.expand(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
        ),
        child: Stack(
          children: <Widget>[
            Positioned(
              top: 0,
              left: 0,
              bottom: 0,
              right: 0,
              child: PhotoView(
                imageProvider: imageProvider, //AssetImage 或 NetworkImage
                loadingChild: loadingChild, //等待加载时的widget
                backgroundDecoration: backgroundDecoration,
                // minScale: minScale,
                // maxScale: maxScale, 不知道默认值设多大
                heroAttributes: PhotoViewHeroAttributes(tag: heroTag),
                enableRotation: true,
              ),
            ),
            Positioned(
              //右上角关闭按钮
              right: 10,
              top: MediaQuery.of(context).padding.top,
              child: IconButton(
                icon: Icon(
                  Icons.close,
                  size: 30,
                  color: Colors.white,
                ),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}

class FadeRoute extends PageRouteBuilder {
  //制作渐隐界面
  final Widget page;
  FadeRoute({this.page})
      : super(
          pageBuilder: (
            BuildContext context,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
          ) =>
              page,
          transitionsBuilder: (
            BuildContext context,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
            Widget child,
          ) =>
              FadeTransition(
            opacity: animation,
            child: child,
          ),
        );
}
